import {
  AuthStateInterface,
  AuthActionTypes,
  LOGIN_TYPE,
  LOGOUT,
  SESSION_LOGIN,
  LOGOUT_WEB
} from './types'

export const initialStateAuth: AuthStateInterface = {
  user: '',
  icon: '',
}

export default (initialState: AuthStateInterface) => {
  return function(
    state = initialState,
    action: AuthActionTypes
  ): AuthStateInterface {
    switch (action.type) {
      case LOGIN_TYPE:
        return {
          ...state,
          icon: action.value.icon,
          user: action.value.user,
        }
      case LOGOUT_WEB:
      case LOGOUT:
        return {
          ...state,
          icon: '',
          user: '',
        }
      case SESSION_LOGIN:
        return {
          ...state,
          icon: action.value.icon,
          user: action.value.user,
        }
      default :
        return state
    }
  }
}